<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    class EventEmitter {
      constructor() {
        this.subs = Object.create(null);
      }
      $on(event, handler) {
        this.subs[event] = this.subs[event] || [];
        this.subs[event].push(handler)
      }
      $emit(event) {
        if (this.subs[event]) {
          this.subs[event].forEach(handler => {
            handler();
          });
        }
      }
    }
    const event = new EventEmitter()
    event.$on('click', () => { console.log('click') })
    event.$on('click', () => { console.log('click') })
    event.$emit('click')
  </script>
</body>

</html>